// __PUBLIC__/js/page/admin/content/denounce
require(['../../common'], function() {
  require(['content.denounce'])
})

define('content.denounce', [
  'jquery',
  'page/grid'
], function($, Grid) {
  'use strict';

  var $table = $('.table')
  var mygrid = new Grid($table)
  mygrid.init()

  $(document)
    .on('click', '.A_del', function(e) {
      e.preventDefault()
      deleteRecord(getASelected(this))
    })
    .on('click', '.A_pass', function(e) {
      e.preventDefault()
      passReview(getASelected(this))
    })
    .on('click', '#J_del', function(e) {
      e.preventDefault()
      deleteRecord(getSelected())
    })
    .on('click', '#J_pass', function(e) {
      e.preventDefault()
      passReview(getSelected())
    })
    .on('click', '#J_search', function(e) {
      e.preventDefault()
      sureSearchDenounce()
    })

  function getSelected() {
    var selected = mygrid.getSelected()
    if (!selected.count) {
      alert(lang.pleaseSelectAData)
      return
    }
    return selected
  }

  function getASelected(t) {
    var current = mygrid.getCurrent(t)
    var selected = {
      id: [current.id],
      index: [current.index]
    }
    return selected
  }

  function deleteRecord(selected) {
    $.post(APP + '?app=admin&m=Content&a=deleteDenounce', {
      ids: selected.id.join()
    })
      .done(function(res) {
        if (res == '1') {
          alert(lang.delSuccess)
          mygrid.del(selected.index)
        } else {
          alert(lang.delFails)
        }
      })
  }

  function passReview(selected) {
    $.post(APP + '?app=admin&m=Content&a=reviewDenounce', {
      ids: selected.id.join()
    })
      .done(function(res) {
        if (res == '1') {
          alert(lang.reviewSuccess)
          mygrid.del(selected.index)
        } else {
          alert(lang.reviewFails)
        }
      })
  }

  function sureSearchDenounce() {
    var id = $('#id').val()
    var uid = $('#uid').val()
    var fuid = $('#fuid').val()
    var from = $('#from').val()
    var state = $('#state').val()
    var str_get = '&id=' + id + '&uid=' + uid + '&fuid=' + fuid + '&from=' + from + '&state=' + state
    location.href = APP + '?app=admin&m=Content&a=denounce' + str_get
  }
    
  $('#J_more').on('click', function(e) {
    e.preventDefault()
    $(this).next('.more-constraints').toggle()
  })
})
